package com.hqj;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients //启用Feign注解
public class Consumer9001Starter {

    public static void main(String[] args) {
        SpringApplication.run(Consumer9001Starter.class,args);
    }

    /**
     * 通过@Bean注解，让spring容器管理RestTemplate实例，
     * 用于协调调用/消费eureka的服务
     * 有@LoadBalanced 表示开启负载均衡 REST  restTemplate.getForObject(),不需要ip,可以根据名称访问
     * 没有@LoadBalanced 表示不开启负载均衡restTemplate.getForObject() 使用ip
     *
     * @return
     */
    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

}
